package com.zhhtech.zhh.ui.dialog

import com.lxj.xpopup.XPopup
import com.lxj.xpopup.core.CenterPopupView
import com.zhhtech.zhh.R
import com.zhhtech.zhh.api.api
import com.zhhtech.zhh.api.core.launchUI
import com.zhhtech.zhh.api.core.toData
import com.zhhtech.zhh.bean.CaseOrderBean
import com.zhhtech.zhh.databinding.DialogSchemeResultBinding
import com.zhhtech.zhh.ui.helper.ILoa

class SchemeResultDialog(
    private val loa: ILoa,
    private val mCaseOrderBean: CaseOrderBean,
) : CenterPopupView(loa.mLoaContext!!) {
    override fun getImplLayoutId() = R.layout.dialog_scheme_result
    private lateinit var vb: DialogSchemeResultBinding
    override fun onCreate() {
        super.onCreate()
        vb = DialogSchemeResultBinding.bind(contentView)
        vb.tvLoanType.text = mCaseOrderBean.loanType
        vb.tvAmount.text = mCaseOrderBean.amount
        vb.tvPlan.text = mCaseOrderBean.plan.joinToString("\n")
        vb.tvConfirm.setOnClickListener { dismiss() }
        vb.tvKefu.setOnClickListener {
            loa.mLoaLifecycleOwner?.launchUI({
                val config = api.indexConfig().toData()
                val mWeComDialog = WeComDialog(loa.mLoaContext!!, config?.weComImg ?: mutableListOf(), config?.phone ?: "")
                XPopup.Builder(context)
                    .isDestroyOnDismiss(true)
                    .asCustom(mWeComDialog)
                    .show()
            })
        }
    }
}